package com.qcby.springbootdemotest.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.util.EntityUtils;
import java.io.IOException;

public class XXDemo {
    public static void main(String[] args) {

        CloseableHttpClient httpClient = HttpClients.createDefault();
        try {

            HttpGet httpGet = new HttpGet("http://123.56.229.59/SEORD002387/DataManageRequest?action=GetRealTimeDynamicChartData3&monitorName=23020372&mpointName=d1&sensorValueName=%E5%8A%A0%E9%80%9F%E5%BA%A6&curAutoID=0");
            // 设置请求头
            httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
            httpGet.setHeader("Accept-Encoding", "gzip, deflate");
            httpGet.setHeader("Accept-Language", "zh-CN,zh;q=0.9");
            httpGet.setHeader("Cache-Control", "max-age=0");
            httpGet.setHeader("Connection", "keep-alive");
            httpGet.setHeader("Cookie", "JSESSIONID=97BAD7087B19C06AB1C24E7680BDF429; UserName=admin; UserRight=admin; SECKEY_ABVK=LnW7n3e3z9JRT4vDKcij9tg4qZftJd1MEu8SZpd7aW/jy9uyOO7NODVtTuLZGBwca8/QG4FZ8hSWJmHxKMe9Ew%3D%3D; BMAP_SECKEY=LnW7n3e3z9JRT4vDKcij9tg4qZftJd1MEu8SZpd7aW8aRhLXP0LACsAX5RuXJM0gOsDsA7niJGvXI9eHOSkv7nlxZ5Nny7rveqgB9E8YqvjVqHHngFbYa5HJ-N2AJ4tXUtiqqKJpWJ-3JQqNK_rPzlsmoc_utTDOeYRrATarmVDuz4uxgg93KX7fS8ehvPFr_Wa-igeyVZAXyRaTpFoUhQ; prjID=1; prjName=%E5%8C%97%E6%96%B9%E5%AD%A6%E9%99%A2%E4%BD%93%E8%82%B2%E9%A6%86");
            httpGet.setHeader("Host", "123.56.229.59");
            httpGet.setHeader("Upgrade-Insecure-Requests", "1");
            httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36");

            // 执行请求
            CloseableHttpResponse response = httpClient.execute(httpGet);

            // 获取响应实体
            String responseBody = EntityUtils.toString(response.getEntity(),"UTF-8");

            // 输出响应内容
           // System.out.println(responseBody);

            //JSON解析
            JSONArray json =  JSON.parseArray(responseBody);
            System.out.println(json.size());
            System.out.println(json.get(0));
            // 关闭响应对象
            response.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                httpClient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }



}
